<template>
  <div class="max-box">
    <div class="header-box">
      <div class="header-left">
        <span>旋转支架</span>
      </div>
    </div>
    <div class="content-box">
      <div class="list-box">
        <div class="weather-box">
          <div class="one-msg" v-for="item in rotatingData">
            <span>{{ item.title }}：</span>
            <span class="one-detail"
              >{{ item.value }} {{ item.value == "--" ? "" : item.unit }}</span
            >
          </div>
        </div>
      </div>

      <div class="mode-set">
        <span>设置模式：</span>
        <div class="mode">
          <span @click="setMode(1)">自动</span>
          <span class="left-box" @click="setMode(0)">停止</span>
        </div>
      </div>
      <myTable :columns="columns" :dataSource="tableData" :myPageShow="false">
      </myTable>
    </div>
  </div>
</template>
<script>
import { rotateList, rotateSetMode } from "@/api/rotatingSupport";
export default {
  data() {
    return {
      rotatingData: [
        {
          title: "设备注册数",
          unit: "个",
          prop: "deviceRegisterNumber",
          value: "--",
        },
        {
          title: "设备在线数",
          unit: "个",
          prop: "deviceLineNumber",
          value: "--",
        },
        {
          title: "状态",
          unit: "",
          prop: "status",
          value: "--",
        },
        {
          title: "异常",
          unit: "",
          prop: "alarm",
          value: "--",
        },
        {
          title: "时间",
          unit: "",
          prop: "deviceTime",
          value: "--",
        },
        {
          title: "DST",
          unit: "",
          prop: "dst",
          value: "--",
        },
        {
          title: "SOC",
          unit: "%",
          prop: "batteryCapacity",
          value: "--",
        },
        {
          title: "Voltage",
          unit: "V",
          prop: "batteryVoltage",
          value: "--",
        },
        {
          title: "SMPS电压",
          unit: "V",
          prop: "smpsVoltage",
          value: "--",
        },
        {
          title: "24V电压",
          unit: "V",
          prop: "lowVoltage",
          value: "--",
        },
        {
          title: "经度",
          unit: "degree",
          prop: "longitude",
          value: "--",
        },
        {
          title: "纬度",
          unit: "degree",
          prop: "latitude",
          value: "--",
        },
        {
          title: "海拔",
          unit: "meter",
          prop: "altitude",
          value: "--",
        },
        {
          title: "风速",
          unit: "m/s",
          prop: "windSpeed",
          value: "--",
        },
        {
          title: "风向",
          unit: "degree",
          prop: "windDirect",
          value: "--",
        },
        {
          title: "降水量",
          unit: "mm",
          prop: "precipitation",
          value: "--",
        },
        {
          title: "降水强度",
          unit: "mm/h",
          prop: "precipitationStrength",
          value: "--",
        },
        {
          title: "降水类型",
          unit: "",
          prop: "precipitationType",
          value: "--",
        },
        {
          title: "水深",
          unit: "mm",
          prop: "waterDepth",
          value: "--",
        },
        {
          title: "雪厚",
          unit: "mm",
          prop: "snowDepth",
          value: "--",
        },
        {
          title: "辐射",
          unit: "W/m2",
          prop: "radiation",
          value: "--",
        },
        {
          title: "温度",
          unit: "℃",
          prop: "temp",
          value: "--",
        },
        {
          title: "更新时间",
          unit: "",
          prop: "createTime",
          value: "--",
        },
      ],
      columns: [
        {
          title: "名称",
          dataIndex: "trackerTitle",
        },
        {
          title: "模式",
          dataIndex: "mode",
        },
        {
          title: "状态",
          dataIndex: "status",
        },
        {
          title: "异常",
          dataIndex: "alarm",
        },
        {
          title: "电机1(A)",
          dataIndex: "motorCurr1",
        },
        {
          title: "电机2(A)",
          dataIndex: "motorCurr2",
        },
        {
          title: "电机3(A)",
          dataIndex: "motorCurr3",
        },
        {
          title: "电机4(A)",
          dataIndex: "motorCurr4",
        },
        {
          title: "SOC(%)",
          dataIndex: "batteryCapacity",
        },
        {
          title: "SMPS电压(v)",
          dataIndex: "smpsVoltage",
        },
        {
          title: "Voltage(v)",
          dataIndex: "batteryVoltage",
        },
        {
          title: "24V电压(v)",
          dataIndex: "lowVoltage",
        },
        {
          title: "目标角度(degree)",
          dataIndex: "targetAngle",
        },
        {
          title: "实时角度(degree)",
          dataIndex: "realAngle",
        },
        {
          title: "更新时间",
          dataIndex: "createTime",
        },
      ],
      tableData: [],
    };
  },
  methods: {
    getRotateList() {
      rotateList().then((res) => {
        console.log(res);
        this.rotatingData.forEach((item) => {
          if (item.prop == "dst") {
            item.value = res.data[item.prop] == 1 ? "是" : "否";
          } else {
            item.value = res.data[item.prop] || "--";
          }
          this.tableData = res.data.rotateTrackerEntities;
        });
      });
    },
    setMode(mode) {
      rotateSetMode({ mode }).then((res) => {
        if (res.code == "000000") {
          this.$message.success(`设置${mode == 0 ? "停止" : "自动"}模式成功`);
        }
      });
    },
  },
  mounted() {
    this.getRotateList();
  },
};
</script>
<style lang="less" scoped>
.max-box {
  width: 100%;
  padding-top: 16px;
  height: 100%;
  padding-right: 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  .header-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    // padding-right: 20px;
    margin-bottom: 16px;
    .header-left {
      span {
        font-size: 18px;
        color: #252b3a;
      }
      i {
        font-size: 20px;
      }
    }
  }
  .content-box {
    background: #fff;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding-bottom: 40px;
    flex-grow: 1;
    .list-box {
      flex-grow: 1;
      .weather-box {
        height: 100%;
        overflow-y: auto;
        display: grid;
        padding: 16px;
        box-sizing: border-box;
        grid-template-columns: repeat(4, 1fr); /* 三列等宽 */
        grid-auto-rows: 50px; /* 自动调整行高度 */
        grid-gap: 10px; /* 列间距和行间距，可根据需要调整 */
        .one-msg {
          font-size: 12px;
          color: #00000073;
          .one-detail {
            color: #515561;
          }
        }
      }
    }
    .mode-set {
      margin: 20px 0;
      font-size: 16px;
      color: #252b3a;
      padding-left: 20px;
      display: flex;
      .mode {
        color: #048fff;
        cursor: pointer;
        .left-box {
          margin-left: 20px;
        }
      }
    }
  }
}
</style>